//餐厅类
function Diningroom(money,seat,worker){
    this.money = money
    this.seat = seat
    this.worker = worker
    this.danli = null
    this.menu = []
    this.addMenu = function (obj){
      for(let i = 0;i<obj.length;i++){
        this.menu.push(obj[i])
      }
    }
    this.recruit= function(obj){
      console.log('招聘方法')
      this.worker.push(obj)
    }
    this.fire = function(obj){
      console.log('解雇方法')
      for(let i=0;i<this.worker.length;i++){
        if(obj.id == this.worker[i].id){
          this.worker.splice(i,1)
          return
        }
      }
    }

}
Diningroom.createDanli = function(money,seat,worker){
    if(!this.danli){
      return this.danli = new Diningroom(money,seat,worker)
    }
    return this.danli
}

// 职员类
function Worker(id,name,pay){
     this.id = id
     this.name = name
     this.pay = pay 
     this.isArry = function(obj){
        return Object.prototype.toString.call(obj)== '[object Array]';
     }
}
// 服务员类
function Waiter(id,name,pay){
  Worker.call(this,id,name,pay)
  this.type = 1
  this.instance = null
  this.tongzhiCooker = function(obj){
     console.log('通知厨师做'+ obj[0].name)
     return obj
  }
}
Waiter.prototype = Object.create(Worker.prototype);
Waiter.careteNew = function(id,name,pay){
    if(!this.instance){
      return this.instance = new Waiter(id,name,pay)
    }
    return this.instance
}

// 厨师类
function Cooker(id,name,pay){
  Worker.call(this,id,name,pay)
  this.type = 2
  this.instance = null

}
Cooker.prototype = Object.create(Worker.prototype);
Cooker.careteNew = function(id,name,pay){
  if(!this.instance){
      return this.instance = new Cooker(id,name,pay)
    }
    return this.instance
}
// 顾客类
function Visitor(name){
   this.money = null
   this.name = name
   this.count = function(arr){
     let total = 0;
     for(let i= 0;i<arr.length;i++){
       total += arr[i].price
     }
     return total
   }
   this.order = function(){
     let num = Math.floor(Math.random()*5);
     if(num == 0) num = 1
     console.log(canding.menu)
     let menu = canding.menu.slice(0,num);
     this.money = this.count(menu) 
     console.log(this)
     return menu
   }
   this.eat = function(obj){
     console.log('顾客吃' + obj.name)
   }
   this.paymoney = function(){
      console.log('顾客付钱' + this.money)
   }
}
// 菜品类
function Food(name,cost,price,time){
     this.name = name
     this.cost = cost
     this.price = price
     this.time = time
}

Worker.prototype.complete = function(obj){
    if(this.type == 1){
      if(this.isArry(obj)){
        // console.log(obj)
        console.log('服务员记录客人点菜', obj)
        return obj
      }
      console.log('服务员上菜' , obj)
      return obj
     
     
    }else if(this.type == 2){
      // console.log(obj)
      console.log('厨师做好' , obj)
      return obj
    }
      
}